#include <stdio.h>
#include <math.h>
int getbig(int);
int getsml(int);
//拉跨的命名
int main()
{
    int res;
    int in;
    int bg, sm;
    int count = 0;
    scanf("%d", &in);

    do
    {
        count += 1;
        bg = getbig(in);
        sm = getsml(in);
        res = bg - sm;
        printf("%d: %d - %d = %d\n", count, bg, sm, res);
        in = res;
    } while (res != 495 || res == 0);

    //printf("%d\n%d",getbig(in),getsml(in));
    return 0;
}
int getbig(int n)
{
    int g, s, b;
    int res;
    b = n / 100;
    n = n % 100;
    s = n / 10;
    g = n % 10;
    if (g >= s && s >= b)
        res = g * 100 + s * 10 + b;
    if (g >= b && b >= s)
        res = g * 100 + b * 10 + s;
    if (s >= b && b >= g)
        res = s * 100 + b * 10 + g;
    if (s >= g && g >= b)
        res = s * 100 + g * 10 + b;
    if (b >= s && s >= g)
        res = b * 100 + s * 10 + g;
    if (b >= g && g >= s)
        res = b * 100 + g * 10 + s;
    return res;
}
int getsml(int n)
{
    int g, s, b;
    int res;
    b = n / 100;
    n = n % 100;
    s = n / 10;
    g = n % 10;
    if (g >= s && s >= b)
        res = b * 100 + s * 10 + g;
    if (g >= b && b >= s)
        res = s * 100 + b * 10 + g;
    if (s >= b && b >= g)
        res = g * 100 + b * 10 + s;
    if (s >= g && g >= b)
        res = b * 100 + g * 10 + s;
    if (b >= s && s >= g)
        res = g * 100 + s * 10 + b;
    if (b >= g && g >= s)
        res = s * 100 + g * 10 + b;
    return res;
}